﻿using System;

namespace Borg.Console.Contracts
{
    public class CommandNotFoundException : Exception
    {
        public string Name { get; private set; }

        public CommandNotFoundException(string name)
            : base(string.Format("Command '{0}' not found", name))
        {
            Name = name;
        }
    }

    public class InnerException : Exception
    {
        public InnerException(Exception inner)
            : base("", inner)
        { }

        public static Exception Unwrap(Exception e)
        {
            return e is InnerException ? e.InnerException : e;
        }
    }

    public class ParameterException : Exception
    {
        public ParameterException(string message)
            : base(message)
        { }
    }

    public class ParameterSyntaxException : ParameterException
    {
        public ParameterSyntaxException(string message)
            : base(message)
        { }
    }

    public class NameAlreadyExistsException : Exception
    {
        public string Name { get; private set; }

        public NameAlreadyExistsException(string name)
            : base(string.Format("Name '{0}' already exists", name))
        {
            Name = name;
        }
    }

    public class InvalidNumberOfParametersException : ParameterSyntaxException
    {
        public InvalidNumberOfParametersException()
            : base("Invalid number of parameters")
        { }

        public InvalidNumberOfParametersException(string message)
            : base(message)
        { }
    }

    public class InvalidParameterValueException : ParameterException
    {
        public int Index { get; private set; }
        public string ParameterValue { get; private set; }

        public InvalidParameterValueException(int index, string parameterValue, string message)
            : base(string.Format("Invalid value '{1}' for parameter {0}: {2}", index, parameterValue, message))
        { }
    }

    public class TooManyParametersException : InvalidNumberOfParametersException
    {
        public TooManyParametersException()
            : base("Too many parameters")
        { }
    }

    public class TooFewParametersException : InvalidNumberOfParametersException
    {
        public TooFewParametersException()
            : base("Too few parameters")
        { }
    }
}
